<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends HomeAction {
 
   
    public function index2(){  
        $email = '402580954@qq.com';  //PS:这不两会嘛，反映民情给胡主席的邮件~~

        $title = '农村医保现存问题的深入剖析';  //标题

        $content = '这里我就不邪恶了~';  //邮件内容
        for($i=1;$i<=30;$i++){
          if(SendMail($email,$title,$content)){
             //   dump('4132');
            }else{
               // dump('error'); 
            }; 
        }
        //直接调用发送即可

    }
    public function js(){  
         $this->display('Test:js');
    }
    
    public function index(){
         
        $group=M('Groups');   
        $art=M('Article');  
        $list=array(
             array('id'=>1,'sortname'=>'公益-支教'),
             array('id'=>2,'sortname'=>'IT-编程'),
             array('id'=>3,'sortname'=>'娱乐-生活'),
             array('id'=>4,'sortname'=>'医学-钻研'));
        foreach($list as $key=>$value){ 
            $gdata=$group->where(array('group_sort'=>$value['id']))->order('gid desc')->limit(5)->select();
            foreach($gdata as $gkey=>$gvalue){ 
                $data['group_id'] = $gvalue['gid'] ;
                $data['state'] = 2;
                $field='aid,name,state';
                $artlist=$art->where($data)->field($field)->group('aid')->order('aid desc')->limit(5)->select(); 
                $gdata[$gkey]['article']=$artlist;
            }
            $list[$key]['group']=$gdata;
            $length=count($list[$key]['group'] );   
            $long=2 -$length % 2 ;    
            if($long != 2){ 
                for ($i =0; $i < $long; $i++) {
                     $list[$key]['group'][]["gid"]= "0" ;
                     $length++;
                }
            } 
            $list[$key]['length'] = $length/2;
        } 
           $this->assign('list',$list); 
        //公益博客
//        $gydata=$group->where(array('group_sort'=>1))->order('gid desc')->limit(20)->select();
//        $this->assign('gygroup_list',$gydata);
//        //IT博客
//        $itdata=$group->where(array('group_sort'=>2))->order('gid desc')->limit(20)->select();
//        $this->assign('itgroup_list',$itdata);
//        //生活博客
//        $shdata=$group->where(array('group_sort'=>3))->order('gid desc')->limit(20)->select();
//        $this->assign('shgroup_list',$shdata);
//        //医学博客 
//        $yxdata=$group->where(array('group_sort'=>4))->order('gid desc')->limit(20)->select();
//        $this->assign('yxgroup_list',$yxdata);
        //查询最新关键字
        $key=M('Keyword');
        $keylist=$key->order('id desc')->limit(20)->order('id desc')->select();
        $this->assign('key_list',$keylist);
        //查询最热文章
         $share=M('Article');  
         $sharelist=$share->field('aid,group_id,name')->limit(20)->order('aid desc')->select();
         $this->assign('article_list',$sharelist);
         
        $this->display('index_new');
    }
   public function indextag(){
        $group=M('Groups');
        $data=$group->select();
        $this->assign('group_list',$data);
        $this->display();
    }
   
    public function ArticleList(){
        
        $share=M('Article');  
        $data['state'] = 2 ;
        import("@.ORG.Page");       //导入分页类
        $count =$share->where($data)->count();//计算总数
        $p = new Page($count, 20);
        $field='aid,uid,group_id,create_time,uname,name,content,group_name,use_count,useless_count,state';
        $sharelist=$share->where($data)->field($field)->group('aid')->order('aid desc')->limit($p->firstRow . ',' . $p->listRows)->select();
    
        // dump($sharelist);
         $p->setConfig('header', '条据');
         $p->setConfig('first', '<li>44</li>');
        
         $p->setConfig('last', '<li></li>');
         $page = $p->show();
         // dump($page);
         $this->assign("page", $page);
         $this->assign('article_list',$sharelist);
         $this->display('article_list');
    }
   
}